import { defineStore } from 'pinia'
import { ref } from 'vue'

// 命名规范：use+名称+Store   第一个参数为唯一标识
export const useAiStore = defineStore(
	'sms-ai',
	() => {
		// ai建议
		const aiSuggestion = ref<any[]>([])

		// 存储ai建议
		const saveAiSuggestion = (subject: number, suggestion: string) => {
			aiSuggestion.value[subject] = suggestion
		}

		// 清除特定科目的AI建议
		const clearAiSuggestion = (subject: number) => {
			if (aiSuggestion.value[subject]) {
				aiSuggestion.value[subject] = null
			}
		}

		// 清除所有AI建议
		const clearAllAiSuggestions = () => {
			aiSuggestion.value = []
		}

		// 检查是否有特定科目的AI建议
		const hasAiSuggestion = (subject: number): boolean => {
			return !!aiSuggestion.value[subject]
		}

		// 暴露
		return {
			aiSuggestion,
			saveAiSuggestion,
			clearAiSuggestion,
			clearAllAiSuggestions,
			hasAiSuggestion
		}
	},
	{
		persist: true // 开启持久化
	}
)
